package cn.itcast.n8;

import cn.itcast.n2.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.util.Comparator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BinaryOperator;
import java.util.function.UnaryOperator;


/**
 * @author: AirMan
 * @date: 2025/4/21 17:23
 * @description:
 */
@Slf4j(topic = "c.TestThreadPoolExecutors_my")
public class TestThreadPoolExecutors_my {

    public static void main(String[] args) {

        AtomicInteger i = new AtomicInteger(1);

        ExecutorService threadPool = Executors.newFixedThreadPool(3, new ThreadFactory() {
            AtomicInteger j = new AtomicInteger(1);
            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "pool_" + j.getAndIncrement());
            }
        });

        threadPool.execute(() -> {
            log.debug("result: "+ i.getAndIncrement());
            Sleeper.sleep(1);
            i.getAndIncrement();
            log.debug("end 1");
        });

        threadPool.execute(() -> {
            log.debug("result: "+ i.getAndIncrement());
            Sleeper.sleep(1);
            i.getAndIncrement();
            log.debug("end 2");
        });

        threadPool.execute(() -> {
            log.debug("result: "+ i.getAndIncrement());
            Sleeper.sleep(1);
            i.getAndIncrement();
            log.debug("end 3");
        });

        threadPool.shutdownNow();
        System.out.println(11111);

    }
}
